import { Component, OnInit } from '@angular/core';
import { uniqueId } from 'lodash';
import { SelectFilterConfig, OptionItem } from '@iux/live';


@Component({
  selector: 'app-demo6',
  templateUrl: './demo6.component.html',
  styles: []
})
export class Demo6Component implements OnInit {

  data: OptionItem[];
  selectedValue;

  constructor() {}

  ngOnInit() {
    this.initData();
  }

  initData() {
    this.data = Array.from({length: 10}).map((item, key) => {
      return this.initUser(key, key % 2 !== 0);
    });

    this.selectedValue = [this.data[0]];
  }

  initUser(key: number, disabled: boolean) {
    return {
      id: uniqueId('uid'),
      label: `user${key}`,
      age: 10 + key,
      expand: false,
      random: parseInt(Math.random() * 100 + ''),
      disabled: disabled,
      isLeaf: true
    };
  }

  filterChange(value: string) {
    console.log('search value', value);
  }

  change(value) {
    console.log('change', value)
  }

  customFilter(data: any, filter: SelectFilterConfig) {
    if (!filter.value) { return true;}
    return data.label.toLowerCase().includes(filter.value.toLowerCase());
  }
}
